﻿using RimWorld;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
using Verse.Sound;

namespace SZ.Mech
{
    public class CompProperties_MechDie : CompProperties_AbilityEffect
    {
        public EffecterDef centerEffecter;
        public float scale;
        public SoundDef soundExplosion;
        public float EMP;
        public float Flame;

        public CompProperties_MechDie()
        {
            compClass = typeof(CompAbilityEffect_MechDie);
        }
    }
    public class CompAbilityEffect_MechDie : CompAbilityEffect
    {
        public CompProperties_MechDie Properties
        {
            get
            {
                return (CompProperties_MechDie)props;
            }
        }
        public override void Apply(LocalTargetInfo target, LocalTargetInfo dest)
        {
            Pawn self = parent.pawn;
            base.Apply(target, dest);
            Properties.centerEffecter.Spawn(self.Position, self.Map, Properties.scale);


            for(int i=0;i< self.Map.mapPawns.AllPawnsSpawned.Count;i++)
            {
                Pawn mapPawn = self.Map.mapPawns.AllPawnsSpawned[i];
                if (mapPawn.Faction != parent.pawn.Faction)
                {
                    Hediff hediff;
                    if (!mapPawn.health.hediffSet.HasHediff(SZ_DefOf.Mech_Die))
                    {
                        hediff = mapPawn.health.AddHediff(SZ_DefOf.Mech_Die);
                    }
                    else
                    {
                        hediff = mapPawn.health.hediffSet.GetFirstHediffOfDef(SZ_DefOf.Mech_Die);
                    }
                    hediff.Severity += 1f;
                    DamageInfo damageInfo = new DamageInfo(DamageDefOf.EMP, Properties.EMP);
                    mapPawn.TakeDamage(damageInfo);
                    DamageInfo damageInfo2 = new DamageInfo(DamageDefOf.Flame, Properties.Flame);
                    mapPawn.TakeDamage(damageInfo2);
                }
            }
            Properties.soundExplosion.PlayOneShot(new TargetInfo(self.Position,self.Map));

        }
    }
}

